package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Toolbar;

import com.yalantis.phoenix.PullToRefreshView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import yalantis.com.sidemenu.interfaces.Resourceble;

public class  SelectItem extends AppCompatActivity {
    
    private ListView mylistview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select_item);
        setTitle("Welcome,"+LoginWithanim.LoginUserName);

        PullToRefreshView mPullToRefreshView = (PullToRefreshView) findViewById(R.id.pull_to_refresh);
        mPullToRefreshView.setOnRefreshListener(new PullToRefreshView.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mPullToRefreshView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mPullToRefreshView.setRefreshing(false);
                    }
                }, 1000);
            }
        });
        mylistview = (ListView) findViewById(R.id.mylistView);
        mylistview.setAdapter(new ItemAdapter(this, getItem()));
        AdapterView.OnItemClickListener lvListener = new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                if (arg2==0){//笔记本
                    startActivity(new Intent(SelectItem.this,MainActivity.class));
                }
                else if (arg2==1){//备忘录
                    startActivity(new Intent(SelectItem.this,Mono_activity.class));
                }
                else if (arg2==2){//云笔记
                    startActivity(new Intent(SelectItem.this,CloudItem.class));
                }
                else if (arg2==3){//地图
                    startActivity(new Intent(SelectItem.this,MyMap.class));
                }
                else if(arg2==4){//图想识别
                    startActivity(new Intent(SelectItem.this,MyCamera.class));
                }
                else if(arg2==5){//网络访问
                    startActivity(new Intent(SelectItem.this,me_introduce.class));
                }
            }
        };
        mylistview.setOnItemClickListener(lvListener);

        //要显示的数据
    }

    private List<Item> getItem() {
        List<Item> Animals = new ArrayList<>();
        Item an1=new Item("MyNote",R.mipmap.notebook);
        Item an2=new Item("MyMemo",R.mipmap.mono);
        Item an3=new Item("MyCloud",R.mipmap.cloud);
        Item an4=new Item("MyMap",R.mipmap.map);
        Item an5=new Item("Figure recognition",R.mipmap.camera);
        Item an6=new Item("Me",R.mipmap.me);
        Animals.add(an1);
        Animals.add(an2);
        Animals.add(an3);
        Animals.add(an4);
        Animals.add(an5);
        Animals.add(an6);
        return Animals;
    }

    public class ItemAdapter extends ArrayAdapter<Item> {
        private List<Item> Animals;

        public ItemAdapter(Context context, List<Item> Animals) {
            super(context, 0, Animals);
            this.Animals = Animals;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.begin_item, null);
            TextView Name = (TextView) convertView.findViewById(R.id.item_name);
            ImageView picture = (ImageView) convertView.findViewById(R.id.item_image);
            Item anAnimal = Animals.get(position);
            Name.setText(anAnimal.getName());
            picture.setImageResource( anAnimal.getImageResourceId());
            return convertView;
        }
    }


}